export const webList = (self, tiyData) => {
  self.loadingData = true;
  self.$Spin.show();
  tiyData.tData.tabList.length=0;
  self.$apiProduct.getTabs().
  then(function (response) {
    if(response.success){
      response.result.forEach(function(item){
        tiyData.tData.tabList.push(item);
      })
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.hide();
    })

}
export const init = (self, tiyData) => {

  // self.$Spin.show();

}

export const add=(self,tiyData)=>{
  tiyData.addModal.isShow=true;
  tiyData.tParam.tab.id='',
  tiyData.tParam.tab.name='',
    tiyData.tParam.tab.icon='',
  this.$refs['tabForm'].resetFields();
}
export const edit=(index,tiyData)=>{
 let row =tiyData.tData.tabList[index];
  tiyData.tParam.tab={id:row.id,name:row.name,icon:row.icon}
  tiyData.addModal.isShow=true;

}
export const actionDelete=(self,tiyData)=>{
  self.loadingData = true;
  self.$Spin.show();
  self.$apiProduct.deleteTab({id:tiyData.tStatus.modalDelete.deleteId}).then(function(response){

    if(response.success){
      self.$Message.success("删除成功");
      webList(self,tiyData);
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.show();
    self.loadingData = false;
  });
}
export const save = (self, tiyData) => {

  tiyData.addModal.isLoading=true;
  self.$refs['tabForm'].validate((valid) => {
    if (valid) {
      self.$Spin.show();
      self.$apiProduct.addEditTab(
        {
          id:tiyData.tParam.tab.id,
          name:tiyData.tParam.tab.name,
          icon:tiyData.tParam.tab.icon,

        }
      ).then(function(response){
        if(response.success){
          self.$Spin.hide();
          tiyData.addModal.isLoading=false;
          self.$Message.success('保存成功');
          tiyData.addModal.isShow=false;
          webList(self,tiyData);
        }else{
          self.$Spin.hide();
          tiyData.addModal.isLoading=false;
          self.$Message.error(response.errorMessage);
        }
      })
    }else{
      changeModelLoading(self, tiyData);
    }
  })

}

function changeModelLoading(self, tiyData) {
  tiyData.addModal.isLoading = false;
  self.$nextTick(function () {
    tiyData.addModal.isLoading = true;
  });
}
